

function bindvalidator() {

	initvalidator();
	$("#deptform").validate({onkeyup:false, submitHandler:function (form) { 
     	 //获取表单提交数据
		var treeType= $.trim($("#treeType").val());		//部门类型
		var fDId= $("#nodeId").val();
		var udId=$("#udId").val();
		var deptName=$("#deptName").val();
		var udPhone=$("#udPhone").val();
		var udTel=$("#udTel").val();
		var udFax=$("#udFax").val();
		var leader=$("#leader").val();//负责人id
	//	alert("负责人id："+leader)
		if(leader.length==0) leader="noneUser";
		
	//	alert("fDId: "+fDId+" udId: "+udId+" deptName:"+deptName+" udTel:"+udTel);
	//	f();
		//alert("treeType: "+treeType+"nodeId"+udId);
		var req;
		if(findLeaderSueecss==false) return false;
		 if(udId===null || udId === "") 
			 req = {"dtypeId":treeType,"udName":deptName, "udPhone":udPhone, "udTel":udTel, "fDId":fDId, "udFax":udFax,"leader":leader};
		 else 
			 req = {udId:udId,udName:deptName, udPhone:udPhone, udTel:udTel, fDId:fDId, udFax:udFax,"leader":leader};
		var url = "../do/dept_saveOrUpdateDept.action";		
		$.post(url, req, function (data) {		
		//	alert(data.result);
			$("#udId").val(udId);
			$("#deptName").val(deptName);
			$("#udPhone").val(udPhone);
			$("#udTel").val(udTel);
			$("#udFax").val(udFax);
			//alert("树的类型"+treeType);
			if(data.result=="success!") window.location.href="../do/medicineTree_getLocalMedicineTreeServiceChildren.action?nodeId="+fDId+"&treeType="+treeType;
				$('#menuFrame',window.parent.document).attr("src","../../do/medicineTree_mtMedicineTreeRoot.action?treeType="+treeType);
			
		});		
	//	$("#addedit").removeClass("blockd");
	//	$("#addedit").addClass("noned");
	//	$("#addedit").dialog("close");
		
		return false;
	}, rules:{"deptName":{required:true},"udPhone":{required:true, isMobile:true},"udTel":{required:true,isTel:true},"udFax":{required:false,isTel:true}}, messages:{"deptName":{required:"*\u5fc5\u987b\u586b\u5199"},"udPhone":{required:"*\u5fc5\u987b\u586b\u5199",isMobile:"\u8bf7\u586b\u5165\u6709\u6548\u7684\u624b\u673a\u53f7\u7801"},"udTel":{required:"*\u5fc5\u987b\u586b\u5199",isTel:"\u8bf7\u586b\u5165\u6709\u6548\u7684\u7535\u8bdd\u53f7\u7801"},"udFax":{isTel:"\u8bf7\u586b\u5165\u6709\u6548\u7684\u7535\u8bdd\u53f7\u7801"}}});

}
function initvalidator() {
	
	jQuery.validator.addMethod("chinese", function (value, element) {
		//alert("chinese validator");
		var chinese = /^[\u4e00-\u9fa5]+$/;
		return this.optional(element) || chinese.test(value);
	}, "\u8bf7\u8f93\u5165\u4e2d\u6587");
	jQuery.validator.addMethod("isMobile", function (value, element) {
		//alert("Mobile validator");
		var length = value.length;
		var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;
		return this.optional(element) || (length == 11 && mobile.test(value));
	}, "\u8bf7\u6b63\u786e\u586b\u5199\u60a8\u7684\u624b\u673a\u53f7\u7801"); 
	
	// 电话号码验证      
	jQuery.validator.addMethod("isTel", function (value, element) {
		//alert("Tel validator"); 
		var tel = /^\d{3,4}-?\d{7,9}$/;    //电话号码格式010-12345678  
		return this.optional(element) || (tel.test(value));
	}, "\u8bf7\u6b63\u786e\u586b\u5199\u60a8\u7684\u7535\u8bdd\u53f7\u7801,\u683c\u5f0f010-12345678");
	
	// 联系电话(手机/电话皆可)验证  
	jQuery.validator.addMethod("isPhone", function (value, element) {
		//alert("Phone validator");
		var length = value.length;
		var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;
		var tel = /^\d{3,4}-?\d{7,9}$/;
		return this.optional(element) || (tel.test(value) || mobile.test(value));
	}, "\u8bf7\u6b63\u786e\u586b\u5199\u60a8\u7684\u8054\u7cfb\u7535\u8bdd");
}



